package com.petHis.project.system.financial.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.petHis.framework.aspectj.lang.annotation.Log;
import com.petHis.framework.aspectj.lang.enums.BusinessType;
import com.petHis.project.system.financial.domain.FinancialRecord;
import com.petHis.project.system.financial.service.IFinancialRecordService;
import com.petHis.framework.web.controller.BaseController;
import com.petHis.framework.web.domain.AjaxResult;
import com.petHis.common.utils.poi.ExcelUtil;
import com.petHis.framework.web.page.TableDataInfo;

/**
 * 财务收支记录Controller
 * 
 * @author petHis
 * @date 2025-02-24
 */
@Controller
@RequestMapping("/system/financial")
public class FinancialRecordController extends BaseController
{
    private String prefix = "system/financial";

    @Autowired
    private IFinancialRecordService financialRecordService;

    @RequiresPermissions("system:financial:view")
    @GetMapping()
    public String financial()
    {
        return prefix + "/financial";
    }

    /**
     * 查询财务收支记录列表
     */
    @RequiresPermissions("system:financial:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FinancialRecord financialRecord)
    {
        startPage();
        List<FinancialRecord> list = financialRecordService.selectFinancialRecordList(financialRecord);
        return getDataTable(list);
    }

    /**
     * 导出财务收支记录列表
     */
    @RequiresPermissions("system:financial:export")
    @Log(title = "财务收支记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FinancialRecord financialRecord)
    {
        List<FinancialRecord> list = financialRecordService.selectFinancialRecordList(financialRecord);
        ExcelUtil<FinancialRecord> util = new ExcelUtil<FinancialRecord>(FinancialRecord.class);
        return util.exportExcel(list, "财务收支记录数据");
    }

    /**
     * 新增财务收支记录
     */
    @RequiresPermissions("system:financial:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存财务收支记录
     */
    @RequiresPermissions("system:financial:add")
    @Log(title = "财务收支记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FinancialRecord financialRecord)
    {
        return toAjax(financialRecordService.insertFinancialRecord(financialRecord));
    }

    /**
     * 修改财务收支记录
     */
    @RequiresPermissions("system:financial:edit")
    @GetMapping("/edit/{recordId}")
    public String edit(@PathVariable("recordId") Long recordId, ModelMap mmap)
    {
        FinancialRecord financialRecord = financialRecordService.selectFinancialRecordByRecordId(recordId);
        mmap.put("financialRecord", financialRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存财务收支记录
     */
    @RequiresPermissions("system:financial:edit")
    @Log(title = "财务收支记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FinancialRecord financialRecord)
    {
        return toAjax(financialRecordService.updateFinancialRecord(financialRecord));
    }

    /**
     * 删除财务收支记录
     */
    @RequiresPermissions("system:financial:remove")
    @Log(title = "财务收支记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(financialRecordService.deleteFinancialRecordByRecordIds(ids));
    }
}
